import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.List;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://www.baidu.com");
        //找到百度输入框
//        WebElement element = webDriver.findElement(By.cssSelector(".s_ipt"));
        //通过xpath定位元素
        WebElement element = webDriver.findElement(By.xpath("//*[@id=\"kw\"]"));
        //输入软件测试
        element.sendKeys("软件测试");
        webDriver.findElement(By.cssSelector("#su")).click();
        //必须进行休眠 , 给系统反应的时间 , 要不然不能正常打印
        Thread.sleep(3000);
        List<WebElement> elements = webDriver.findElements(By.cssSelector("a em"));
        for (int i = 0;i<elements.size();i++){
            System.out.println(elements.get(i).getText());
        }
    }
}